<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Test extends Site {

    function setup() {
        $this->run_modes('test');
        $this->start_mode('test');
        $this->selfurl = '/testxml.php';
        parent::setup();
    }

    function cgiapp_prerun() {

        parent::cgiapp_prerun();
    }

    function action_test() {

        $xmlObj = simplexml_load_file("http://www.fashionguide.com.tw/beauty/Api/TopicMsgInfL_imore_u8.asp?act=20090821&diaxczh=ieqoj");

        if ($xmlObj) {
            foreach ($xmlObj as $value_row) {

                $insert = array('resDuration' => trim($this->xml2Str($value_row->resDuration)));
                db_update('fg_product', $insert, 'num=' . trim($this->xml2Str($value_row->num)));
                echo $value_row->num . "<br>";
            }
        }
    }

    function xml2Str($obj) {
        return trim((string) $obj);
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new Test();
$webapp->run();
?>